New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ScalaIDE container to the Eclipse classpath for Scala projects #99
Conversation
Hey! Thanks for the pull request. Can you double check how this implementation behaves in this scenario:
AFAIK, the scala container only adds the 'scala-library' on the path. If it also adds other dependencies, we need to make sure the project imports smoothly if the Gradle project already declares similar dependencies explicitly. |
Can you please clarify the expectations between disjoint versions? Scala only provides backwards compatibility for minor versions (e.g. 2.9.0 to 2.9.2). It does not guarantee compatibility between major revisions (e.g. 2.9.x to 2.10.x). While much of the core is expected to stabilize as the language ages, most cross-version mixing is unsafe. Using a version of the ScalaIDE that does not match the major version in the build file would be considered an invalid configuration. This is why the ScalaIDE includes a classpath validator (see faq), which seems to be all that the container adds. The compatibility problem is explained by Suereth and Odersky, with coding strategies to avoid issues. I'll try your scenarios tomorrow. |
I want to make sure that the project imports cleanly to eclipse if it already has scala library. I don't have any specific versions in mind. Cheers! |
A little searching and an additional concern was raised on the ScalaIDE forum. I have not encountered the specs2 issue, but was able to verify that full rebuilds are being performed instead of incremental. What do you think the proper fix is for that issue? |
Right now Gradle does not do incremental compiles for Scala. We are aware that this is an important issue. We have already successfully spiked a solution by integrating with the SBT compiler. Right now we are planning to tackle this feature in Gradle 1.3 with a high priority. So possibly there will be a solution in a couple of weeks. |
The incremental compilation referred to is through the Eclipse Scala Builder, which is backed by an embedded copy of SBT. The generated Eclipse metadata causes the ScalaIDE to not perform incremental compilation. I think that it is separate from gradle native support. It may be a ScalaIDE bug depending on interpretation. |
Hey Ben, I'm not convinced that having 2 conflicting versions of scala-library on the IDE build path is healthy. You've tested it and apparently it does not break anything. I had problems with that few months ago (I don't remember what version of scala IDE / scala-library I have used) - the build in IDE didn't work in that scenario (however, I don't remember what was the exact problem). Anyway, to fix the problem I needed to remove the container from the project. Not sure what to do with the problem that the scala ide requires its very own version of scala library for the incremental compilation to work. Is this a bug that the scala IDE team wants to fix at some point? I'm wondering about:
I need touch base with the team how we want to approach it. |
Hi Szczepan, I suspect that you used disjoint versions (e.g. 2.9.x in Gradle, 2.10.x in Eclipse). That would be a really easy mistake to make by naively taking the latest version and not realizing the incompatibility issues. I haven't tested that scenario since it could lead to a lot of surprising failures. I definitely agree with (2) and I can try to make those changes to my pull request if agreed to. I'm less convinced of (1) because I haven't seen the problem occur. When your team decides on the preferred approach, we can ask on the Scala IDE mailing list for one of their developers to offer feedback. |
Hey, We're leaning towards solution 2 but we haven't yet concluded :)
Are you already on this mailing list? Can lead the effort and ask the Scala IDE guys? Cheers! |
requested feedback from ScalaIDE team. |
I'm a Scala IDE committer. I'm very glad to see support from Gradle!
I don't know if Gradle already does it, but it would be great if it attached sources to jars, so in case the exported project definition does not have the Scala container, the scala-library.jar comes with sources and hyperlinking still works. For reference, |
The ScalaIDE 2.9x nightly appears to work perfectly. This is with Scala 2.9.2 gradle dependency and Scala 2.9.3-(nightly #) as the Scala Library. I attempted to revert back to a stable release and reproduce the problem, but forgetting my original version I was unable to confidently identify a problem in v2.0.2. I was assuming full vs. incremental compiles for a project based on the speed of the build. If the ScalaIDE and gradle dependency used the same version of Scala then the build was immediate. If they differed by a minor version then the build was much slower. The change was to modify a single character in a Scalatra route. Given the behavior of the nightly build, I don't consider this to be a problem anymore. I am in favoring of being consistent the rest of the ScalaIDE ecosystem. The With respect to attaching sources to jars, the EclipseClasspath has downloadSources enabled by default ("Whether to download and add sources associated with the dependency jars. Defaults to true."). |
Thanks a lot for the research and feedback. Let's go for the option with replacing the scala-library with the scala container. @ben, can you prepare a new pull request? :) Please remember about:
Thanks a lot! |
Thanks Iulian and Szczepan! I'd like to keep this pull request open until I have the code changes ready. I'll then close this request and start the new one so that the discussions can focus on the code review. That way these improvements don't fall off the radar as we work on the coding. I will be participating in college career fair events next week so my changes may be delayed. Please note that since I am unaffiliated with Gradle or Scala teams, feel free to push forward if my progress becomes too slow. I'll work on the five points opportunistically, but may have other commitments that take precedence. |
Hey @ben, There's no rush. Feel free to work on the items in whatever order / time you like. We won't push on the implementation because of other priorities on our end. Bear in mind that we'd rather pull the request if all the items are completed (e.g. integ tests, docs, etc :) It would be really helpful if you used fresh fork so that we don't have to review old commits. Thanks a lot and good luck! |
I finally got back to this and have a partial solution. The only way I could find to remove the dependencies within However, when importing with the Gradle STS plugin the dependencies are still listed. I suspect that it is using the Gradle Tooling API instead to retrieve the list of external dependencies. I'm unsure how best to proceed so that the removal of the external dependencies can be seen by gradle tooling. |
I realized a better approach that works is effectively, The only problem with this is that the scalaTools includes different dependencies than the ones that the ScalaIDE adds, so I have to dynamically create a configuration object. I'm trying to figure out the best way now. It would be very helpful if a Gradle dev was available to chat for guidance. The freenode irc channel is unresponsive. |
I have finished all items, rebased my branch, and squashed all changes into a single commit. Please let me know if you'd still prefer that we close this pull request and open a new one to focus on the code. I'm happy to continue this one. I decided to add a
The only two solutions remaining was to either have the build file specify the Scala version or add a new configuration type. I am unsure why the Scala plugin preferred the latter approach, but it set the precedent and expectation of how the Scala project should be configured. This is similar to how the idea-scala-facet plugin added a A benefit of the approaches taken is that I was able to add them as build customizations into my projects until Gradle includes the improved support. The build file now emulates these fixes by including, eclipse.classpath {
minusConfigurations += configurations.scalaIde
containers += ["org.scala-ide.sdt.launching.SCALA_CONTAINER"]
} |
Thanks for the investigation. I need to think about it a bit more. |
Please let me know if there is anything else that I can do so that v1.3 contains ScalaIDE support. That could be either the proposed code changes, documenting only the build customizations, or another alternative. I'd like to see a documented fix in v1.3 due to the awesome work towards native incremental compilation support. The build customizations has been a positive improvement for my engineering team by making Eclipse much more usable. |
Hey Ben,
I've discussed this issue with Peter. We think it should be possible to configure the minusConfigurations with a detached configuration that contains the same scala library dependency as the declared by the user. What exactly was the problem? In general we would like to follow above path. E.g. detached configuration with scala library, assigned to minusConfigurations. |
Updated to use a detached configuration by waiting until all projects were evaluated before inspecting the dependencies. In addition to the tests, I verified with a scala project by inspecting the This is thanks for Peter's answer to a similar problem on StackOverflow, where he advised using |
The ScalaIDE classpath container is now added when to projects using the Scala plugin. This resolve build problems after importing a Scala project due to the ScalaIDE not being able to add its dynamically computed entries to the classpath of the project. The ScalaIDE adds the Scala libraries to the classpath, which duplicates the dependencies provided by Gradle. In the ScalaIDE v2.0.2, having multiple entries for scala-library results in full builds instead of incremental). A detatched configuration allows projects to exclude the dependencies from being provided by Gradle, which matches the SBT and Maven behavior.
Thanks for the pull request. It's part of Gradle 1.3. |
The ScalaIDE plugin is the standard approach for developing Scala projects in Eclipse. Previously an import of a Scala gradle project would initially fail to build due to the error 'Cannot find Scala library on the classpath. Verify your build path!'. This had to be resolved manually so that the ScalaIDE verifier could be run successfully.
The ScalaIDE is now added as a classpath container. In addition to the unit test, the change was verified on a private project. The container was added to Scala projects only (and not Java projects).
Further background details is provided in the forum post, Generate ScalaIDE Eclipse metadata for Scala projects.